﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunnyFunction
{
    class RomeNumber
    {
        private static List<RD> rList = new List<RD>()
        {
            new RD(1,"I"),
            new RD(4,"IV"),
            new RD(5,"V"),
            new RD(9,"IX"),
            new RD(10,"X"),
            new RD(40,"XL"),
            new RD(50,"L"),
            new RD(90,"XC"),
            new RD(100,"C"),
            new RD(400,"CD"),
            new RD(500,"D"),
            new RD(900,"CM"),
            new RD(1000,"M"),
        };

        public static string N2R(int num)
        {
            if (num < 0 || num > 3999)
            {
                return $"超出转换范围: {num}";
            }
            string result = "";
            while (num>0)
            {
                var pair = rList.Last(t => t.num <= num);
                result += pair.rm;
                num -= pair.num;
            }

            return result;
        }
    }

    class RD
    {
        public int num;

        public string rm;

        public RD(int n, string r)
        {
            this.num = n;
            this.rm = r;
        }
    }
}
